//
//  ViewController.m
//  20--Homework
//
//  Created by 冀永金 on 16/8/10.
//  Copyright © 2016年 冀永金. All rights reserved.
//

#import "ViewController.h"
#import "XMLReader.h"
#import "MovieModel.h"
@interface ViewController ()<NSXMLParserDelegate>
@property (nonatomic, strong) NSMutableArray *movieMarray;
@property (nonatomic, copy) NSString *currentName;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    NSString *path = [[NSBundle mainBundle] pathForResource:@"Cartoon" ofType:@"xml"];
    NSData *data = [NSData dataWithContentsOfFile:path];
    NSXMLParser *xmlParser = [[NSXMLParser alloc]initWithData:data];
    xmlParser.delegate = self;
    [xmlParser parse];
    // Do any additional setup after loading the view, typically from a nib.
}
- (void)parserDidStartDocument:(NSXMLParser *)parser {
    self.movieMarray = [NSMutableArray array];
}
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary<NSString *,NSString *> *)attributeDict {
    _currentName = elementName;
    if ([elementName isEqualToString:@"AlbumInfo"]) {
        MovieModel *model = [[MovieModel alloc]init];
        [_movieMarray addObject:model];
    }
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
    if (_currentName) {
        MovieModel *model = [_movieMarray lastObject];
        [model setValue:string forKey:_currentName];
        NSLog(@"-----%@",string);
    }
}

- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
    _currentName = nil;
    
}
- (void)parserDidEndDocument:(NSXMLParser *)parser {
    NSLog(@"++++++%@",_movieMarray);
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
